﻿// <copyright file="AnalyticsEvent.cs" company="Microsoft Corporation">
// Copyright (c) 2009 Microsoft Corporation All Rights Reserved
// </copyright>
// <author>Michael S. Scherotter</author>
// <email>mischero@microsoft.com</email>
// <date>2010-10-16</date>
// <summary>AnalyticsEvent class definition</summary>

namespace Microsoft.WebAnalytics
{
    using System;
    using System.Collections.ObjectModel;
#if !SILVERLIGHT
    using System.Drawing;
#endif
    using System.Runtime.Serialization;
#if SILVERLIGHT
    using System.Windows;
    using System.Windows.Media;
#endif
    using Microsoft.WebAnalytics.Data;

    /// <summary>
    /// A web analytics event
    /// </summary>
    [DataContract(Name = "AE", Namespace = "http://schemas.microsoft.com/webanalytics/2010")]
    public class AnalyticsEvent
    {
        /// <summary>
        /// Initializes a new instance of the AnalyticsEvent class
        /// </summary>
        public AnalyticsEvent()
        {
            this.EventArgs = new Collection<PropertyValue>();
            this.HitType = HitType.Event;
        }

        /// <summary>
        /// Gets or sets the name of the group of objects that are tracked
        /// </summary>
        [DataMember(Name = "C", IsRequired = false, EmitDefaultValue = false)]
        public string Category { get; set; }

        /// <summary>
        /// Gets or sets the hit type
        /// </summary>
        [DataMember(Name = "HT")]
        public HitType HitType { get; set; }

        /// <summary>
        /// Gets or sets the Timestamp for the event
        /// </summary>
        [DataMember(Name = "TS")]
        public DateTimeOffset Timestamp { get; set; }

        /// <summary>
        /// Gets or sets the name of the event
        /// </summary>
        [DataMember(Name = "N")]
        public string Name { get; set; }

        /// <summary>
        /// Gets or sets The name of the object that this event is associated with
        /// </summary>
        [DataMember(Name = "ON", IsRequired = false, EmitDefaultValue = false)]
        public string ObjectName { get; set; }

#if SILVERLIGHT
        /// <summary>
        /// Gets or sets the media stream type during a SSME TrackChanged event
        /// in a Silverlight application
        /// </summary>
        [DataMember(Name = "MST", IsRequired = false, EmitDefaultValue = false)]
        public MediaStreamType? MediaStreamType { get; set; }
#endif

        /// <summary>
        /// Gets or sets the time code from the application startup
        /// </summary>
        [DataMember(Name = "TC", IsRequired = false, EmitDefaultValue = false)]
        public TimeSpan TimeCode { get; set; }

        /// <summary>
        /// Gets or sets the time code from the beginning of the media stream
        /// </summary>
        [DataMember(Name = "MTC", IsRequired = false, EmitDefaultValue = false)]
        public TimeSpan MediaTimeCode { get; set; }

        /// <summary>
        /// Gets or sets the TrackInfo for the SmoothStreamingMediaElement
        /// </summary>
        [DataMember(Name = "T", IsRequired = false, EmitDefaultValue = false)]
        public TrackInfo Track { get; set; }

        /// <summary>
        /// Gets or sets the media source
        /// </summary>
        [DataMember(Name = "MS", IsRequired = false, EmitDefaultValue = false)]
        public Uri MediaSource { get; set; }

        /// <summary>
        /// Gets or sets the referring HTML page 
        /// </summary>
        [DataMember(Name = "R", IsRequired = false, EmitDefaultValue = false)]
        public string Referrer { get; set; }

        /// <summary>
        /// Gets or sets the URI of the document that is hosting the Silverlight control
        /// </summary>
        [DataMember(Name = "DU", IsRequired = false, EmitDefaultValue = false)]
        public Uri DocumentUri { get; set; }

        /// <summary>
        /// Gets or sets the A/B testing state name
        /// </summary>
        [DataMember(Name = "SN", IsRequired = false, EmitDefaultValue = false)]
        public string StateName { get; set; }

        /// <summary>
        /// Gets or sets a numeric value that indicates the relative importance of this event.
        /// </summary>
        [DataMember(Name = "V", IsRequired = false, EmitDefaultValue = false)]
        public int? Value { get; set; }

        /// <summary>
        /// Gets or sets a string that is assocated with an action.  For 
        /// example, with a ComboBox SelectionChanged event, this value would 
        /// be the text of the newly selected item.
        /// </summary>
        [DataMember(Name = "AV", IsRequired = false, EmitDefaultValue = false)]
        public string ActionValue { get; set; }

        /// <summary>
        /// Gets or sets the screen Resolution
        /// </summary>
        [DataMember(Name = "RS", IsRequired = false, EmitDefaultValue = false)]
        public Size Resolution { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether the Silverlight application is in full screen
        /// </summary>
        [DataMember(Name = "FS", IsRequired = false, EmitDefaultValue = false)]
        public bool IsFullScreen { get; set; }

        /// <summary>
        /// Gets or sets the browser zoom factor
        /// </summary>
        [DataMember(Name = "ZF", IsRequired = false, EmitDefaultValue = false)]
        public double ZoomFactor { get; set; }

        /// <summary>
        /// Gets or sets the URI fragment that represents the current navigation state
        /// </summary>
        [DataMember(Name = "NS", IsRequired = false, EmitDefaultValue = false)]
        public string NavigationState { get; set; }

        /// <summary>
        /// Gets or sets the language of the user
        /// </summary>
        [DataMember(Name = "L", IsRequired = false, EmitDefaultValue = false)]
        public string Language { get; set; }

        /// <summary>
        /// Gets or sets the application name (AssemblyTitle Attribute)
        /// </summary>
        [DataMember(Name = "AN", IsRequired = false, EmitDefaultValue = false)]
        public string AppName { get; set; }

        /// <summary>
        /// Gets or sets the application version
        /// </summary>
        [DataMember(Name = "VER", IsRequired = false, EmitDefaultValue = false)]
        public string Version { get; set; }

        /// <summary>
        /// Gets or sets the unique Id of the content
        /// </summary>
        [DataMember(Name = "CID", IsRequired = false, EmitDefaultValue = false)]
        public string ContentId { get; set; }

        /// <summary>
        /// Gets or sets the event arguments
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly", Justification = "Necessary for XAML serialization."), DataMember(Name = "ARG", IsRequired = false, EmitDefaultValue = false)]
        public Collection<PropertyValue> EventArgs { get; set; }

        /// <summary>
        /// Gets or sets the video/audio Clip context
        /// </summary>
        [DataMember(Name = "CL", IsRequired = false, EmitDefaultValue = false)]
        public ClipContext Clip { get; set; }

        /// <summary>
        /// Gets or sets the browser's User Agent
        /// </summary>
        [DataMember(Name = "UA", IsRequired = false, EmitDefaultValue = false)]
        public string UserAgent { get; set; }

        /// <summary>
        /// Gets or sets the Silverlight version
        /// </summary>
        [DataMember(Name = "SV", IsRequired = false, EmitDefaultValue = false)]
        public string SilverlightVersion { get; set; }

#if SILVERLIGHT && !WINDOWS_PHONE 
        /// <summary>
        /// Gets or sets the installation state of the Silverlight Application
        /// </summary>
        [DataMember(Name = "IS", IsRequired = false, EmitDefaultValue = false)]
        public InstallState InstallState { get; set; }
#endif
        /// <summary>
        /// Gets or sets the type of the object that triggers the analytics event
        /// </summary>
        [DataMember(Name = "OT", IsRequired = false, EmitDefaultValue = false)]
        public string ObjectType { get; set; }
    }
}
